<!DOCTYPE html>
<!--
 Copyright (c) 2015 - 2019 fortiss GmbH
               2019 Johannes Kepler University Linz
   
 This program and the accompanying materials are made available under the
 terms of the Eclipse Public License 2.0 which is available at
 http://www.eclipse.org/legal/epl-2.0.

 SPDX-License-Identifier: EPL-2.0
 
 Contributors:
   Milan Vathoopan, Monika Wenger, Jose Cabral
     - initial API and implementation and/or initial documentation
   Bianca Wiesmayr
     - adapting, restructuring and extending the installation tutorial
-->

<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <title>Building 4diac FORTE for Wago</title>
      <link rel="stylesheet" type="text/css" href="../help.css">
   </head>

   <body>
      <h1 id="topOfPage">Building 4diac FORTE for Wago</h1>
      <h2>Introduction</h2>
      <p>Wago PFC 200 series is a PLC designed to work in small and medium enterprises for small-scale automations and runs on an ARM cortex A8, 600 Mhz controller with real-time Linux 3.6 (RT preemption patch). 
      This tutorial helps setting up 4diac FORTE on the WAGO embedded platform. 
      The essentials for following this tutorial are:</p>
	  <ul>
		<li><a href="http://wiki.ubuntuusers.de/Downloads" target="_blank">Ubuntu 14.04 LTS</a> host system with minimum 25 GB Hard Disk space (e.g. as a <a href="https://www.virtualbox.org/" target="_blank">VirtualBox</a> VM)</li>
		<li>Within Ubuntu, download :
			<ul>
				<li><a href="https://www.wago.com/public-download/support/BSP/WAGO-PFC-BSP-latest.zip" target="_blank">WAGO-PFC-BSP</a> Board Support Package (BSP) for configuring and building customized applications on Wago PFCs. 
				<li>Dependencies for Wago BSP
				<ul>
					<li><a href="http://debian.pengutronix.de/debian" target="_blank">OSELAS cross tool chain 2012.12.1</a> for Crotex A8 boards</li>
					<li><a href="http://www.ptxdist.org/software/ptxdist/download/" target="_blank">PTXDist-2013.03.0</a> a GPL-licensed build system for building target embedded Linux kernel and root system from sources.
			    </ul>
			<li><a href="http://www.eclipse.org/4diac/en_dow.php" target="_blank"> Latest version of FORTE source</a> which contains the <span class="specicificText">processInterface</span> for Wago at <span class="folderLocation">forte/src/modules/wagokbus</span>. 
			The <span class="specicificText">processInterface</span> facilitates using Wago analog and digital IOs with generic IX,QX and IW,QW blocks from 4diac IDE. </li>
			</ul>
			</li>
		
	  </ul>
	  <p><span class="attention"><span class="inlineTitle">ATTENTION</span>: 
	  This tutorial is based on WAGO-PFC-BSP-2014.10.3. 
	  The procedure given here is also applicable for the latest board support packages from Wago. 
	  The toolchain and the PTXDist version may also vary based on the BSP version.</span></p>
	  
	  <h2>Wago BSP Installation on Ubuntu Host</h2>
	  <p>DO NOT install the packages within the root folder! 
	  The installation may take over an hour, therefore, be patient till the whole process is complete.</p>
	  <ol>
		<li>Create a folder e.g. <span class="folderLocation">~/Wago</span></li>
		<li>Unzip the board support Package for WAGO PFC downloaded before into the <span class="folderLocation">~/Wago</span> folder.
		 Follow the installation process as found in HOWTo_Install_WAGO_PFC_BSP-version till the step <span class="specificText">Compile all packages of PFC200 Firmware</span>. </li>
	  </ol>
	
	<h2>Building 4diac FORTE</h2>
	<p>4diac FORTE is normally deployed in cross platforms using CMake. 
	Here, for the wago device, all the build process is controlled by <span class="specicificText">ptxdist</span>. 
	For the 4diac FORTE build process it is important to know about a few directories in the wago development environment. 
	All ptxdist packages are managed by so-called rule files. 
	These files are located in the <span class="folderLocation">wago/ptxproj-2.2.20/rules</span> directory. 
	When you create a new package, rule files <span class="fileLocation">packagename.make</span> and <span class="fileLocation">packagename.in</span> are created in the rules directory. 
	There are two kinds of source directories, <span class="folderLocation">wago/src</span> for system level packages and <span class="folderLocation">wago/local_src</span> for new custom packages. 
	The build directory for the target system (i.e., wago) is located in a directory called <span class="folderLocation">platformwago-wago-pfc200/build-target</span>.</p>
	<ol>
		<li>Create a forte_wago project in PTXDist: 
		From <span class="folderLocation">FORTE/buildsupport/wago_pfc200/</span>, copy the rule files <span class="fileLocation">forte_wago.in</span> and <span class="fileLocation">forte_wago.make</span> to <span class="folderLocation">wago/ptxproj-2.2.20/rules</span> (creates a new package). 
		Within the copied rule file <span class="fileLocation">.../ptxproj-2.2.20/forte_wago.make</span> edit the line <span class="specicificText">FORTE_WAGO_URL: file:///&lt;path to 4diac FORTE main directory&gt;</span> to the absolute path of your 4diac FORTE main directory. 
		To (de)activate specific modules (library parts) of 4diac FORTE edit <span class="fileLocation">.../ptxproj-2.2.20/wago.make</span> line <span class="specicificText">FORTE_WAGO_CONF_OPT := ...</span></li>
		
		<li>Save the package to PTXDist: 
		To follow the standard build process of PTXDist the package has to be saved to the PTXDist build environment. 
		Select the <span class="specicificText">forte_wago</span> with space key 
		(This will be displayed as <span class="specicificText">[*]</span>) and press exit to quit. 
		When asked whether you want to save the package, press <span class="button4diac">Yes</span>.

		 <p> <span class="attention"><span class="inlineTitle">NOTE</span>: PTXDist is a command line utility which works only from the defined project environment, for example <span class="folderLocation">~wago/ptxproj-2.2.20</span> directory. The "ptxdist" commands will work only in this directory.</span></p>
		<div class="code">&gt; cd wago/ptxproj-2.2.20
&gt; ptxdist menuconfig</div>
		<img src="../../html/installation/img/wagoManager.png" alt="PTXDist Manager"/></li>
		
		<li>Build the project: 
		Go to your <span class="folderLocation">ptxproj-2.2.20</span> folder and perfom the build instruction as follows to build 4diac FORTE for the target device Wago PFC.
		<div class="code">&gt; cd wago/ptxproj-2.2.20
&gt; ptxdist targetinstall forte_wago</div>
		<img src="../../html/installation/img/wagoConsole.png" alt="Build Project Console Output"/>
		 <p>The binary can be found in the directory <span class="folderLocation">.../ptxproj-2.2.20/platform-wago-pfc200/buid-target/forte_wago-1.6.2-build/src</span>. The binary can be either copied to the target device <span class="folderLocation">/usr/bin</span> directory or you can build your own custom linux image by performing <span class="inlineCode">&lt;ptxdist go&gt;;</span> command in your <span class="folderLocation">ptxproj-2.2.20</span> directory and boot with your own custom firmware.</p></li>
		
		<li>Rebuilding the Project: For rebuilding the project, the project has to be cleaned and perform the <span class="specicificText">targetinstall</span> again.
		<div class="code">&gt; cd wago/ptxproj-2.2.20
&gt; ptxdist clean forte_wago</div>
		This clean instruction deletes the <span class="specicificText">forte_wago</span> build time stamps in the wago development environment. Now performing a <span class="specicificText">targetinstall</span> will rebuild the project
<div class="code">&gt; ptxdist targetinstall forte_wago</div>
		If you made any changes in your forte root folder this changes will be reflected here and you will see the same window as you saw before.</li>
	</ol>
	  
	  
	  <h2>Building and Debugging 4diac FORTE remotely on Wago PFC with Eclipse</h2>
	  <h3>Building 4diac FORTE with Eclipse</h3>
	  <p>4diac FORTE can be debugged remotely from your Ubuntu host machine using Eclipse CDT. 
	  For more details, please refer to Wago on how to Utilize EclipseCDT. 
	  Using the same procedure, 4diac FORTE can be debugged remotely. 
	  The recommended folder structure for building 4diac FORTE in Eclipse is:</p>
	  
	<ul>
		<li> eclipseCDT
			<ul>
				<li>workspace
				<ul>
					<li> forte (contains FORTE source)</li>
					<li> forte-wago (contains project to access the Wago PFC)</li>
				</ul>
				</li>
			</ul>
		</li>
	</ul>
	  
	  <p>Within the forte-wago folder, create a new <span class="specicificText">C Project</span> by 
	  <span class="menu4diac">Menu &rarr; File &rarr; New &rarr; Project</span>, 
	  type a project name, e.g., <span class="specicificText">forte-wago</span>, deactivate default location and set the location to your 4diac FORTE source e.g., <span class="fileLocation">forte</span>. 
	  Choose <span class="menu4diac">Makefile project/Empty Makefile Project</span> and <span class="menu4diac">- Other Toolchain -</span> and press <span class="button4diac">Finish</span>. Set the properties for the new projects. Within the category <span class="menu4diac">C/C++ Build</span> set the <span class="specicificText">Build command</span> to ptxdist and the <span class="specicificText">Build directory</span> to your ptxdist installation location.</p>
	 
	  <img src="../../html/installation/img/wago_eclipse_ptxdist1.png" alt="configure Eclipse with ptxdist"/>
	  
	 <p>Set <span class="menu4diac">Build</span> within the <span class="tab4diac">Behvior</span> tab to <span class="specicificText">targetinstall forte_wago</span> and <span class="specicificText">Clean</span> to <span class="specicificText">clean forte_wago</span>.</p> 
	  
	  <img src="../../html/installation/img/wago_eclipse_ptxdist2.png" alt="add include folders to Eclipse"/>
	  
	 <p>Add the required include directories within the <span class="menu4diac">C/C++ General / Paths and Symbols</span> category. The required include directories are:</p> 
	  
	  <div class="code">.../ptxproj-2.2.20/platform-wago-pfc200/sysroot-target/include

.../ptxproj-2.2.20/platform-wago-pfc200/sysroot-target/usr/include
	  
.../OSELAS.Toolchain-2012.12.1/arm-cortexa8-linux-gnueabihf/
gcc-4.7.3-glibc-2.16.0-binutils-2.22-kernel-3.6-sanitized/include

.../OSELAS.Toolchain-2012.12.1/arm-cortexa8-linux-gnueabihf/
gcc-4.7.3-glibc-2.16.0-binutils-2.22-kernel-3.6-sanitized/
sysroot-arm-cortexa8-linux-gnueabihf/usr/include

.../OSELAS.Toolchain-2012.12.1/arm-cortexa8-linux-gnueabihf/
gcc-4.7.3-glibc-2.16.0-binutils-2.22-kernel-3.6-sanitized/
lib/gcc/arm-cortexa8-linux-gnueabihf/4.7.3/include</div>
	  
	  <img src="../../html/installation/img/wago_eclipse_ptxdist3.png" alt="FORTE build for Wago in Eclipse"/>
	 
	 <p>Within the <span class="view4diac">C/C++</span> perspective right-click on your project and choose <span class="view4diac">Build Project</span> or <span class="menu4diac">Clean Project</span>. 
	 After building your project you should get a <span class="view4diac">Console</span> output as it is shown below.</p>
	 
	 <img src="../../html/installation/img/wago_eclipse_ptxdist4.png" alt="FORTE build for Wago in Eclipse"/>
	 
	 <p>Within the <span class="view4diac">Remote System Explorer</span> perspective, create a <span class="specicificText">New Connection</span> by clicking on <img class="inlineImg" src="../../html/installation/img/wago_newConnectionButton.png" alt="New Connection button"/>. 
	 Choose <span class="specicificText">Linux</span> and press <span class="button4diac">Next</span>. 
	 Enter the IP of our Wago PFC as <span class="specicificText">Host name</span> and type any <span class="specicificText">Connection Name</span>, e.g. <span class="specicificText">wagoPFC200</span> and press Finish. 
	 In the <span class="view4diac">Remote System</span> view, you can log to your Wago PFC by right-clicking on <span class="button4diac">Ssh Terminals</span> and entering <span class="specicificText">root</span> as <span class="specicificText">user</span> and <span class="specicificText">wago</span> as <span class="specicificText">password</span>. 
	 A <span class="view4diac">Terminal</span> view should open as well as a <span class="view4diac">Remote System Details</span> view. </p>
	 
	 <img src="../../html/installation/img/wago_eclipse_ptxdist5.png" alt="FORTE build for Wago in Eclipse"/>
	  
	  <p>Copy the 4diac FORTE executable to <span class="folderLocation">/usr/bin</span> on the Wago PFC. The executable can be copied to the Wago PFC by pasting it into the <span class="folderLocation">/usr/bin</span> folder in the <span class="view4diac">Remote System Details</span> view. Stop the running CoDeSys instance (<span class="specicificText">kill plclinux_rt</span>) if you want to use digital inputs/outputs of the Wago PFC and start 4diac FORTE with:</p>
	  
	  <div class="code">&gt; cd /usr/bin
&gt; ./forte</div>
	  
	  <h3>Debugging 4diac FORTE with Eclipse</h3>
	  <p>To debug 4diac FORTE on a Wago PFC, click on the small triangle next to <img class="inlineImg" src="../../html/installation/img/debug_persp.gif" alt="debug"/> and choose <span class="specicificText">Debug Configurations</span>. 
	  Then, select <span class="specicificText">C/C++ Remote Application</span> and set any name (e.g., <span class="specicificText">forte</span>). 
	  Within the <span class="tab4diac">main</span> tab, set the path to the 4diac FORTE executable under <span class="specicificText">C/C++ Application</span>, set the <span class="specicificText">Project</span> to your chosen project name <span class="specicificText">forte_wago</span>, check <span class="specicificText">Disable auto build</span>, set <span class="specicificText">Connection</span> to your chosen <span class="specicificText">Connection name</span> e.g. <span class="specicificText">wagoPFC200</span> and set the <span class="specicificText">Remote Absolute File Path for C/C++ Application</span> to your 4diac FORTE executable on the Wago <span class="fileLocation">/usr/bin/forte</span>.</p>

	   <img src="../../html/installation/img/wago_debug_eclipse1.png" alt="FORTE debug for Wago in Eclipse"/>
	   
	  <p>Within the <span class="tab4diac">Debugger</span> tab set the <span class="specicificText">GDB debugger</span> to <span class="specicificText">/.../OSELAS.Toolchain-2012.12.1/arm-cortexa8-linux-gnueabihf/gcc-4.7.3-glibc-2.16.0-binutils-2.22-kernel-3.6-sanitized/bin/arm-cortexa8-linux-gnueabihf-gdb</span>.</p>
	   
	  <img src="../../html/installation/img/wago_debug_eclipse2.png" alt="FORTE debug for Wago in Eclipse"/>
	  
	  <p>Debug 4diac FORTE with Eclipse as usual.</p>

<h1 id="whereToGoFromHere">Where to go from here?</h1>

<p>Now that you installed the required tools, it's time to start using them. Take a look at the following page:</p>

<p><a href="../../html/4diacIDE/overview.html">Step by step tutorial</a></p>

<p>If you want to build a 4diac FORTE, here is a quick link back:</p>

<p><a href="../../html/installation/install.html">Install Eclipse 4diac</a></p>

<p>If you want to go back to the Start Here page, we leave you here a fast access</p>

<p><a href="../../html/startHere/startHere.html">Start Here page</a></p>

<p class="goToTop">Or <a href="#topOfPage">Go to top</a></p>

</body>
</html>

